const { contextBridge, ipcRenderer } = require('electron')

ipcRenderer.on('ipcmainHandlerKeys', (_event, ipcmainHandlers) => {
    const electronAPIContent = {};
    ipcmainHandlers.forEach(ipcmainHandlerKey => {
        electronAPIContent[ipcmainHandlerKey] = function(){
            return ipcRenderer.invoke(ipcmainHandlerKey, ...arguments);
        }
    });
    electronAPIContent['onProcessMsg'] = (callback) => ipcRenderer.on('processMsg', (_event, value) => callback(value));
    electronAPIContent['onUsbChange'] = (callback) => ipcRenderer.on('usbChange', (_event, value) => callback(value));
    electronAPIContent.process = process;
    contextBridge.exposeInMainWorld('electronAPI',electronAPIContent);
})